{extend name="base" /}
{block name="content"}
<script language="javascript" type="text/javascript" src="__STATIC__/public/My97DatePicker/WdatePicker.js"></script>
<div class="g-main">
    <div class="m-main-title">
        <div class="m-container-fluid">
            <a href="{:url('index/welcome')}"><i class="icon icon-home"></i>首页</a>
            <span class="icon-angle-right"></span>
            <span>商城</span>
            <span class="icon-angle-right"></span>
            <span>优惠券管理</span>
            <span class="icon-angle-right"></span>
            <span>优惠券管理</span>
            <span class="icon-angle-right"></span>
            <span>{$info ? '编辑' : '添加'}优惠券</span>
            <a class="u-flush"><i class="icon-repeat"></i></a>
        </div>
    </div>
    <div class="m-main-content">
        <div class="m-container">
            <div class="m-form">
                <form class="layui-form" id="j_form">
                    <table class="m-table">
                        <tbody>
                            <tr>
                                <th colspan="2">优惠券信息</th>
                            </tr>
                            <tr>
                                <td width="15%"><label for="coupon_name">优惠券名称<em>*</em></label></td>
                                <td><input type="text" class="u-ipt u-ipt-longer" name="coupon_name" id="coupon_name" placeholder="请输入优惠券名称" value="{$info.coupon_name}" /></td>
                            </tr>
                            <tr>
                                <td width="15%"><label for="description">优惠券描述<em>*</em></label></td>
                                <td><textarea name="description" id="description" style="width:100%;">{$info.description}</textarea></td>
                            </tr>
                            <tr>
                                <td><label for="">优惠券类别<em>*</em></label></td>
                                <td>
                                    <div class="lay-select m-select-def">
                                        <select name="class_id" lay-filter="category_id">
                                            <option value="0">请选择类别</option>
                                            {foreach name="class" item="v"}
                                            <option value="{$v.id}"{if condition="$info['class_id'] eq $v['id']"} selected{/if}>{$v.class_name}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                </td>
                            </tr>

                            <tr>
                                <td width="15%"><label>优惠券类型<em>*</em></label></td>
                                <td>
                                    <input type="radio" lay-filter="coupon_type" name="coupon_type" value="0" title="满减劵" {if
                                           condition=" isset($info['coupon_type']) && ($info['coupon_type'] eq 0)"
                                           } checked{/if} />
                                    <input type="radio" lay-filter="coupon_type" name="coupon_type" value="1" title="抵用券" {if
                                           condition=" isset($info['coupon_type']) && ($info['coupon_type'] eq 1)"
                                           } checked{/if} />
                                </td>
                            </tr>
                            <tr>
                                <td width="15%"><label for="limit_price">限制使用金额<em>*</em></label></td>
                                <td><input type="text" class="u-ipt u-ipt-small" name="limit_price" id="limit_price" placeholder="请输入限制使用金额" value="{$info.limit_price}" {if condition="$info.limit_price neq '' "}readonly{/if} /><span>元</span></td>
                            </tr>
                            <tr>
                                <td width="15%"><label for="offset_price">冲抵金额<em>*</em></label></td>
                                <td><input type="text" class="u-ipt u-ipt-small" name="offset_price" id="offset_price" placeholder="请输入冲抵金额" value="{$info.offset_price}"  {if condition="$info.offset_price neq '' "}readonly{/if}  /></td>
                            </tr>
                            <tr>
                                <td width="15%"><label for="offset_price">优惠券数量<em>*</em></label></td>
                                <td><input type="text" class="u-ipt u-ipt-small"  name="number" id="number" placeholder="请输入优惠券数量" value="{$info.number}" {if condition="$info.number neq '' "}readonly{/if} /></td>
                            </tr>
                            <tr>
                                <td width="15%"><label for="offset_price">剩余数量</label></td>
                                <td><input type="text" class="u-ipt u-ipt-small" name="surplus_number" readonly id="surplus_number" placeholder="" value="{$info.surplus_number}" /></td>
                            </tr>
                            <tr>
                                <td width="15%"><label for="limit_price">有效期开始时间<em>*</em></label></td>
                                <td><input type="text" name="pbegin" class="u-ipt u-ipt-long" id="pbegin" placeholder="开始时间"  value="{$info.pbegin ? date('Y-m-d',$info.pbegin) : date('Y-m-d', time())}" {if condition="$info.pbegin neq '' "}readonly{else/} onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"{/if}></td>
                            </tr>
                            <tr>
                                <td width="15%"><label for="limit_price">有效期结束时间<em>*</em></label></td>
                                <td><input type="text" name="pend" class="u-ipt u-ipt-long" id="pend" placeholder="结束时间" value="{$info.pend ? date('Y-m-d',$info.pend) : date('Y-m-d', time())}" {if condition="$info.pend neq '' "} readonly {else/} onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"{/if}><span>默认到所选日期的23:59:59</span></td>
                            </tr>
                            <tr>
                                <td><label for="">分享图片</label></td>
                                <td>
                                    <button type="button" class="layui-btn u-upload-pic" data-name="share_img"><i class="layui-icon">&#xe67c;</i>上传图片</button>
                                    <div class="m-pic">
                                        <ul>
                                            {:attach_html($info.share_img, 'share_img')}
                                        </ul>
                                    </div>
                                </td>
                            </tr>
                            <input type="hidden" value="{$info.register_time ? $info.register_time : time()}" name="register_time" id="register_time"/>
                        </tbody>
                    </table>
                    <div class="m-form-btn">
                        <input type="hidden" name="id" id="id" value="{$info.id}">
                        <button id="j_btn" type="button" class="u-btn">确定提交</button></div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="extrajs"}
{include file="public:upload"/}
<script src="__STATIC__/public/js/jquery-ui.min.js"></script>
<script>
    $(function () {
        var keyValue;
        keyValue = $("input[name='coupon_type']:checked").val();

        if (keyValue == 0) {
            $("#fl").hide();
            $("#sp").hide();
        }
        if (keyValue == 1) {
            $("#fl").show();
            $("#sp").hide();
        }
        if (keyValue == 2) {
            $("#fl").hide();
            $("#sp").show();
        }
    })
    layui.use('form', function () {
        var form = layui.form;
        form.on('radio(coupon_type)', function (data) {
            if (data.value == 0) {
                $("#fl").hide();
                $("#sp").hide();
            }
            if (data.value  == 1) {
                $("#fl").show();
                $("#sp").hide();
            }
            if (data.value  == 2) {
                $("#fl").hide();
                $("#sp").show();
            }
            form.render();
        });
        form.on('radio(commission_charge_type)', function (data) {
            if (data.value == 0) {
                $('.commission_charge_first').attr("disabled",true);
                $('.commission_charge_second').attr("disabled",true);
            }
            if (data.value  == 1) {
                $('.commission_charge_first').attr("disabled",false);
                $('.commission_charge_second').attr("disabled",false);
            }
            if (data.value  == 2) {
                $('.commission_charge_first').attr("disabled",false);
                $('.commission_charge_second').attr("disabled",false);
            }
            form.render();
        });
    });
</script>
{/block}